home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
dev
/
misc
/
IOBlixDevKitR2.lha
/
IOBlixDevKit
/
C
/
examples
/
QueryParPorts.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-03
|
5KB
|
113 lines
/*
This program is meant to demonstrate how to get all necessary information
about a specific chip on an IOBlix board and how to program that chip in a
system-friendly manner
*/
#include <exec/exec.h>
#include <resources/ioblix.h>
#include <ioblix/parport.h>
#include <stdio.h>
#include <string.h>
#include <proto/exec.h>
#include <proto/ioblix.h>
UBYTE __aligned myname[]="QueryParPorts 37.1 "__AMIGADATE__;
UBYTE __aligned version[]="$VER: QueryParPorts 37.1 "__AMIGADATE__;
UBYTE __aligned copyright[]="(C)opyright 1998,1999 by Thore Böckelmann and RBM Computertechnik. All rights reserved";
struct IOBlixResource *IOBlixBase = NULL;
void main(void)
{
struct IOBlixChipNode *chipNode;
ULONG board;
ULONG unit;
UBYTE *prevOwner;
struct ParPort *pp;
IOBlixBase = (struct IOBlixResource *)OpenResource(IOBLIXRESNAME);
if (IOBlixBase) {
for (board = 0; board < IOBLIX_MAX_Z2_BOARDS; board++) {
for (unit = 0; unit < IOBLIX_Z2_NUM_PARUNITS; unit++) {
/* first simply try to find each parallel port */
/* if it is available then print some information */
chipNode = FindChip(ICT_PARALLEL_Z2_CHIP, board*10+unit);
if (chipNode) {
printf("parallel port %ld on board %ld is a \"%s\" with %ld bytes FIFO\n", unit, board, chipNode->icn_Description, chipNode->icnp_FIFOSize);
printf("current user: %s\n", (chipNode->icn_Owner) ? chipNode->icn_Owner : (UBYTE *)"nobody");
printf("abilities: ");
if (chipNode->icnp_Abilities & PCPAF_SPP) printf("SPP ");
if (chipNode->icnp_Abilities & PCPAF_PPF) printf("PPF ");
if (chipNode->icnp_Abilities & PCPAF_PS2) printf("PS2 ");
if (chipNode->icnp_Abilities & PCPAF_EPP) printf("EPP ");
if (chipNode->icnp_Abilities & PCPAF_ECP) printf("ECP ");
printf("\n");
/* now try to obtain chip for exclusive use */
prevOwner = NULL;
chipNode = ObtainChip(ICT_PARALLEL_Z2_CHIP, board*10+unit, myname, &prevOwner);
if (chipNode) {
/* for this test we need SPP mode and the ability to switch to other modes with */
/* the ECR register */
if ((chipNode->icnp_Abilities & (PCPAF_SPP | PCPAF_ECR)) == (PCPAF_SPP | PCPAF_ECR)) {
UBYTE oecr;
UBYTE testString[] = "The quick brown fox jumps over the lazy dog";
UBYTE readBack[256];
ULONG cnt, writeCnt;
pp = (struct ParPort *)chipNode->icn_Address;
/* now play a bit with the parport's test mode */
/* every value written to the FIFO should also be read back */
/* else something really bad has happened */
oecr = pp->econtrol;
/* first set port in SPP mode, else TST mode cannot be activated */
/* turn off parport interrupts */
pp->econtrol = PARPORT_ECONTROL_SPP | PARPORT_ECONTROL_INT;
pp->econtrol = PARPORT_ECONTROL_TST | PARPORT_ECONTROL_INT;
/* write some data to the FIFO */
cnt = 0;
do {
pp->tfifo = testString[cnt];
cnt++;
} while ((testString[cnt]) && !(pp->econtrol & PARPORT_ECONTROL_FIFO_F));
writeCnt = cnt;
printf("wrote %ld bytes of \"%s\" to FIFO\n", writeCnt, testString);
/* and now read the data back */
cnt = 0;
do {
readBack[cnt] = pp->tfifo;
cnt++;
} while ((cnt < writeCnt));
readBack[cnt] = 0x00;
printf("read %ld bytes from FIFO. \"%s\"\n", cnt, readBack);
/* restore old econtrol contents */
pp->econtrol = PARPORT_ECONTROL_SPP | PARPORT_ECONTROL_INT;
pp->econtrol = oecr;
} else {
printf("parallel port doesn't support anything else than SPP!\n");
}
/* now release the chip again */
ReleaseChip(chipNode);
} else {
/* ObtainChip() failed, so let's check for other owners */
if (prevOwner) printf("chip is already in use by \"%s\"\n", prevOwner);
}
} else {
printf("Parallel port %ld on board %ld is not available\n", unit, board);
}
}
}
} else {
printf("Can't find ioblix.resource. Please run SetupIOBlix\n");
}
}